package com.tsj.ai.mcp.service;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.stereotype.Service;

/**
 * @author taoshujian
 * @version 1.0
 * @since 2025-10-30 09:13:30
 */
@Service
public class GetWeatherService {

    private final ChatClient chatClient;

    public GetWeatherService(ChatClient.Builder chatClientBuilder, ToolCallbackProvider tools) {
        this.chatClient = chatClientBuilder.defaultToolCallbacks(tools).build();
    }

    public String getWeatherInfo(String city) {
        String PROMPT_TEMPLATE = "请根据用户输入的{name}，返回该城市的天气信息";
        Prompt prompt = new Prompt(new UserMessage(PROMPT_TEMPLATE.replace("{name}", city)));

        return chatClient.prompt(prompt).call().content();
    }
}
